package com.thingcom.chinamobile.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.thingcom.base.util.R;
import com.thingcom.chinamobile.dto.DataDto;
import com.thingcom.chinamobile.service.DeviceStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName DataController
 * @Description TODO
 * @Author zhou tao
 * @Date 2019/12/18 9:52
 * @Version 1.0
 **/
@RestController
@RequestMapping("/data")
public class DataController {

	@Autowired
	private DeviceStatusService deviceStatusService;

	@GetMapping("/history")
	public R getHistoryData(DataDto dataDto) {
		JSONObject re = deviceStatusService.getDeviceStatusHisInPage(dataDto);
		R r = R.ok();
		JSONArray deviceDatas = re.getJSONArray("deviceStatusList");
		if (deviceDatas != null && deviceDatas.size() != 0) {
			r.put("deviceDatas", deviceDatas);
			r.put("pageTimestamp", re.getStr("page_timestamp"));
		}

		return r;
	}
}
